<?php
App::uses('AuthComponent', 'Controller/Component');
class User extends AppModel {
	
    public $validate = array(
        'username' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'A username is required'
            )
        ),
        'password' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'A password is required'
            )
        ),
        'role' => array(
            'valid' => array(
                'rule' => array('inList', array('registered', 'managers', 'special', 'admin', 'superadmin')),
                'message' => 'Please enter a valid role',
                'allowEmpty' => false
            )
        )/*,
		'current_password' => array(
			'rule' => 'checkCurrentPassword',
			'message' => 'Invalid old password'
		),
		'password1' => array(
			'passlength' => array(
				'rule'    => array('minLength', '8'),
            	'message' => 'Minimum 8 characters long'
			),
			'passcomplexity' => array(
				'rule'    => 'alphaNumeric',
				'message' => 'Password must  contain letters and numbers.'
			)
		),
		'confirm_password' => array(
			'passmatch' => array(
				'rule' => array('custom', 'comparePasswords'),
				//'rule' => 'comparePasswords',
				'message' => 'Passwords do not match'
			)
		)*/
    );
	
	/*protected function comparePasswords($field = null){
		return ($this->data['User']['password1'] == $this->Auth->password( $this->data['User']['confirm_password']));
        //return (Security::hash($field['confirm_password'], null, true) === $this->data['User']['password']);
		//return($check['password'] == Security::hash(Configure::read('Security.salt').$this->data['User']['confirm_password']));
    }*/
	
	
	public function beforeSave($options = array()) {
		if (isset($this->data[$this->alias]['password'])) {
			$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
		}
		return true;
	}

}
?>